import tensorflow as tf
# (初始值，name)
state = tf.Variable(0,name='counter')
# print(state.name)
one = tf.constant(1)

new_value = tf.add(state , one)
update = tf.assign(state,new_value)
#最重要,初始化所有的变量，如果定义了遍历，必须初始化
init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    for _ in range(3):
        sess.run(update)
        print(sess.run(state))
